<?php

/**
 * @Desc:账户升级接口
 * @author dasheng@baofu.com(大圣)
 * @datetime 2025/4/7 10:27
 */

require_once "../../Init/init.php";

use App\baocaitong3\Entity\ContentBodyEntity as ContentBody;
use App\baocaitong3\Entity\HeaderEntity as Header;
use App\baocaitong3\Entity\PostParmEntity as PostParm;
use App\baocaitong3\Entity\UpgradeInfoEntity as UpgradeInfo;
use App\baocaitong3\SecurityUtil\NewRsaUtil;
use App\baocaitong3\Util\HttpClient;
use App\baocaitong3\Util\Log;
use App\baocaitong3\Util\Tools;

$ServiceTp = "T-1001-013-20";
 
$upgradeacc = new UpgradeInfo();
$upgradeacc->version="4.1.0";
$upgradeacc->contractNo = "CM610000000000175288";
$upgradeacc->qualificationTransSerialNo = "TSN17440105396282";//上传接口返回的流水号
$upgradeacc->province = "浙江省宁";
$upgradeacc->city = "宁波市";
$upgradeacc->district = "镇海区";
$upgradeacc->detailedAddress = "人民大道155号";
$upgradeacc->businessAddress = "浙江省宁波市镇海区人民大道155号 凌云威尼斯8栋3070室";
$upgradeacc->registeredAddress = "浙江省宁波市奉化区玉兰路72号 第5期碧波世纪华庭17栋2242室";
$upgradeacc->legalPersonIdValidityPeriod = "20440506";
$upgradeacc->businessScope = "电子产品制造、服装加工";
$upgradeacc->establishmentDate ="20201023";
$upgradeacc->registeredCapital = "600";
$upgradeacc->businessExecutionValidityPeriod = "20360506";
$upgradeacc->contactMobile = "15984811034";
$upgradeacc->requestNo = Tools::getTsnOderid("RN");

$headerinfo = new Header();
$headerinfo->terminalId = $GLOBALS["TerminalId"];
$headerinfo->memberId = $GLOBALS["MemberId"];
$headerinfo->serviceTp = $ServiceTp;
$headerinfo->verifyType = "1";

$bodycontent = new ContentBody();
$bodycontent->header = $headerinfo;
$bodycontent->body = $upgradeacc;

$ContentStr = json_encode($bodycontent);
Log::EchoFormat("JSON序列号：".$ContentStr);
$enContent = NewRsaUtil::encryptByPfx($ContentStr,$GLOBALS["PFX_PATH"],$GLOBALS["KeyPwd"]);

$postParm = new PostParm();
$postParm->memberId = $GLOBALS["MemberId"];
$postParm->terminalId = $GLOBALS["TerminalId"];
$postParm->content = $enContent;


$ResultPost  = HttpClient::Post($postParm,"https://vgw.baofoo.com/union-gw/api/".$ServiceTp."/transReq.do");
Log::EchoFormat("返回参数：".$ResultPost);
if(empty($ResultPost)) throw new Exception("请求返回异常");

if(strpos($ResultPost,"header") != false)
{
    $resulterror = json_decode($ResultPost,true);
    var_dump($resulterror);
}else{
    $DePostString = NewRsaUtil::decrptByPub($ResultPost,$GLOBALS["CER_PATH"]);
    Log::EchoFormat("解密返回：".$DePostString);
    if(empty($DePostString))  throw new Exception("解密空值，请检查证书是否正常");
    if(strpos($DePostString,"header"))
    {
        $contenBe = json_decode($DePostString,true);
        if($contenBe["header"]["sysRespCode"] === "S_0000")
        {
            Log::EchoFormat("业务层结果:".json_encode($contenBe["body"]));
            if($contenBe["body"]["retCode"] === 1){
                Log::EchoFormat("升级受理成功:".json_encode($contenBe["body"]));
            }else{
                Log::EchoFormat("查询失败:".json_encode($contenBe["body"],JSON_UNESCAPED_UNICODE));
            }
        }
    }
}



